/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.registration.business.security.entity;

import java.io.Serializable;
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;

/**
 *
 * @author Stefano
 */

@Entity
public class GroupFriend implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @NotNull
    private int id;

    @NotNull(message = "May not be empty")
    private String name;
    
    
    @ManyToOne(optional = false)
    private User owner;

    @OneToMany
    private List<User> belongers;    
    
    public GroupFriend() {
    }
    
    public GroupFriend(String name, User owner)
    {
        this.name=name;
        this.owner=owner;
        this.belongers= new LinkedList<User>();
    }
    
    public boolean isIntheList(User user)
    {
        if(this.belongers.contains(user))
        {
            return TRUE;
        }
        else 
            return FALSE;
    }
    
    public GroupFriend(String name) {
        this.name = name;
    }
  
    
    public List<User> getbelongers() {
        return this.belongers;
    }

    public void setBelongers(User id) {
        this.belongers.add(id);
    }
   
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    public User getOwner() {
        return owner;
    }

    public void setOwner(User owner) {
        this.owner = owner;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int) id;
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof GroupFriend)) {
            return false;
        }
        GroupFriend other = (GroupFriend) object;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.registration.business.security.entity.GroupLabel[ id=" + id + " ]";
    }
    
}
